Resister value calculation
/* Name : Main.c * Purpose : Source code for LEDs Interfacing with ATMEGA16. * Author : GEMICATES * Date : 04-07-2017 * Website : www.gemicates.org * Revision : None */ #include<avr/io.h> // Header File for ATMEGA16 #include<util/delay.h> // Include Delay Function #define LEDS PORTA // To Set Port A as Output #define L1 PB0 // To Set Port B pin 0 as Output #define L2 PD7 // To Set Port D pin 7 as Output #define SW PD0 // To Set Port D pin 0 as Input // MAIN FUNCTION void main() { DDRA =0xff; // Set the Data Direction Register A as Ouput DDRB =0x01; // Set the Data Direction Register B Pin 0 as Ouput DDRD =0x80; // Set the Data Direction Register D Pin 7 as Ouput & Pin 0 as Input PORTD=0x01; // Enable the Pullup Resistor for Switch while(1) // Infinite loop { LEDS=0x00; // Enable the PortA Pins PORTB =~(1<<L1); // Enable the PortB Pin 0 _delay_ms(500); // Make Delay LEDS=0xff; // Diable the PortA Pins PORTB =(1<<L1); // Enable the PortB Pin 0 _delay_ms(500); // Make Delay if (PIND == 1) // Check Switch Position { PORTD =(1<<L2); // If Switch is ON LED Connected to the pin PD7 will Enable _delay_ms(500); // Make Delay PORTD =0; // Disable the Pin PD7 _delay_ms(500); // Make Delay } } }